#ifndef __FENCE_BLOCK_H__
#define __FENCE_BLOCK_H__

#include "Block.hpp"
#include "IPaintableBlock.hpp"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    class BlocksManager;

    // 栅栏方块基类
    class FenceBlock : public Block, public IPaintableBlock
    {
    public:
        FenceBlock();
        virtual void initialize() override;
        virtual void getCreativeValues(std::vector<int32_t> &blockVec) override;
        virtual void getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues) override;
        virtual bool shouldConnectTo(int32_t value);

        virtual int32_t getPaintColor(int32_t value) override;
        virtual int32_t paint(int32_t value, int32_t color) override;

        static inline int32_t GetColor(int32_t data);
        static inline int32_t SetColor(int32_t data, int32_t color);
        static inline int32_t GetVariant(int32_t data);
        static inline int32_t SetVariant(int32_t data, int32_t variant);
    };

    inline int32_t FenceBlock::GetColor(int32_t data)
    {
        if ((data & 0x10) != 0)
        {
            return (data >> 5) & 0xF;
        }
        return -1;
    }
    inline int32_t FenceBlock::SetColor(int32_t data, int32_t color)
    {
        if (color != -1)
        {
            return (data & -497) | 0x10 | ((color & 0xF) << 5);
        }
        return data & -497;
    }

    inline int32_t FenceBlock::GetVariant(int32_t data)
    {
        return data & 0xF;
    }
    inline int32_t FenceBlock::SetVariant(int32_t data, int32_t variant)
    {
        return (data & -16) | (variant & 0xF);
    }

} // namespace PocketSurvival

#endif
